'''
PDDL Merge and Translator - Pre Process Input

Author: Dr. Patricia Riddle @ 2013
Contact: pat@cs.auckland.ac.nz

Translates PDDL files using an automated planner in order to improve performance

Functions to pre process input files

-------

Copyright (C) 2013  Dr. Patricia Riddle, University of Auckland

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

'''

import sys
import subprocess

def remove_comments(filename):    
    inputstring = ""
    with open(filename, "r") as f:
        for line in f:
            inputstring = "%s%s" % (inputstring, line)

    awk_cmd = "awk -F';' '{ print $1 }'"
    process = subprocess.Popen(awk_cmd, shell=True,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)

    out, err = process.communicate(inputstring)
    errcode = process.returncode

    return str(out)

if __name__ == "__main__":

    print remove_comments(sys.argv[1])
    
